{% extends 'layout.html' %}
{% load web %}
{% block content %}
    <div class="luffy-container">
        <h1>项目：{{ project.title }}</h1>
        <div>
            <a class="btn btn-primary" href="{% memory_url request 'deploy_add' project_id=project.id %}">添加</a>
{#             <a class="btn btn-danger" href="{% memory_url request 'deploy_rollback_list' project_id=project.id   %}">回滚</a>#}
        </div>



        <table class="table table-bordered">
            <thead>
            <tr>
                <th>版本</th>
                <th>文件名称</th>
                <th>状态</th>
                <th>获取</th>
                <th>发布</th>
                <th>回滚</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            {% for row in depart_queryset %}
                <tr>

                    <td>{{ row.version }}</td>
                    <td>{{ row.uid }}</td>
                    <td>{{ row.get_status_display }}</td>
                    <td>
                        <a onclick="buildCode(this,{{ project.id }},{{ row.id }});">获取代码</a>
                        <div style="display: inline-block;" class="hide">
                            <img style="height: 17px" src="/static/imgs/loading.gif" alt="">
                        </div>
                    </td>
                    <td>
                        <a href="{% memory_url request 'deploy_push' project_id=project.id deploy_id=row.id  %}">发布</a>

                    </td>
                    <td>
                        <a href="{% memory_url request 'deploy_rollback' project_id=project.id deploy_id=row.id  %}">回滚</a>

                    </td>

                    <td>
                        <a href="{% memory_url request 'deploy_edit' project_id=project.id nid=row.id %}">编辑</a>
                        <a href="{% memory_url request 'deploy_del' project_id=project.id nid=row.id %}">删除</a>
                    </td>

                </tr>
            {% endfor %}
            </tbody>
        </table>
        <nav aria-label="Page navigation">
            <ul class="pagination">
                {{ pager.page_html|safe }}
            </ul>
        </nav>

    </div>
{% endblock %}

{% block js %}
    <script>


    function buildCode(ths,projectid,deployid) {
        $(ths).next().removeClass('hide');
        {#请求url#}
        var buildUrl="/deploy/fetch/"+projectid+"/"+deployid+"/";
        $.ajax({
            url:buildUrl,
            type:"get",
            dataType:"json",
            success:function (arg) {
                if(arg.code){
                    {#所处状态#}
                    $(ths).parent().prev().text(arg.status);
                    {#文件名#}
                    $(ths).parent().parent().prev().text(arg.uid)
                }


                  $(ths).next().addClass('hide');
                
            }

        })
        
    }
    </script>

{% endblock %}